/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution114 {

    public static void main(String args[]){
        Solution114 s = new Solution114();
    }

    public void flatten(TreeNode root) {
        dfs(root);
    }

    public void dfs(TreeNode cur){
        if(cur == null){
            return;
        }
        dfs(cur.left);
        dfs(cur.right);

        TreeNode r = cur.right;
        cur.right = cur.left;
        TreeNode c = cur;
        while(c.right != null){
            c = c.right;
        }
        c.right = r;
        cur.left = null;
    }
}
